<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${r'${pageContext.request.contextPath}'}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
	<title>${sysCname}</title>
	<script src="${r'${ctx}'}/common/plateform/base/jquery/jquery.min.js"></script>
	<script src="${r'${ctx}'}/common/plateform/base/bootstrap/bootstrap.min.js"></script>
	<link href="${r'${ctx}'}/common/plateform/base/bootstrap/bootstrap.min.css" rel="stylesheet">
	<link href="${r'${ctx}'}/common/plateform/plugins/adminlte/AdminLTE.css" rel="stylesheet">
	<script src="${r'${ctx}'}/common/plateform/base/layer/layer.js"></script>
	<link href="${r'${ctx}'}/common/plateform/base/fonts/font-awesome.min.css" rel="stylesheet">
	<link href="${r'${ctx}'}/common/plateform/base/utils/plateform.css" rel="stylesheet" />
	<link href="${r'${ctx}'}/common/plateform/base/utils/mystyle.css" rel="stylesheet" />
	<script src="${r'${ctx}'}/common/plateform/base/utils/jquery-md5-min.js"></script>
	<!--[if gte IE 6]>
	<script src="${r'${ctx}'}/common/plateform/plugins/ie/html5shiv.min.js"></script>
	<script src="${r'${ctx}'}/common/plateform/plugins/ie/respond.js"></script>
	<![endif]-->
	<script>
        var ctx = '${r'${ctx}'}';
	</script>
	<script type="text/javascript">
        function viewVerifyCode() {
            var r = "";
            if (undefined != ctx)
                r = ctx;
            document.getElementById("verifyCode").style.visibility = "visible";
            document.getElementById("verifyCode").src = ctx + "/web/CheckRandCode?" + Math.random();
        }
	</script>
</head>
<style>
	.login_wrap {
		background: url("${r'${ctx}'}/images/plateform/login_bg_plateform2.jpg") no-repeat;
		background-size: 100%;
		margin-top: 10px;
	}
</style>

<body>
<div class="container">
	<h1 class="login_title ">
		<p class="pull-left"><p>${sysCname}</p> <span>欢迎登录！</span></p>
	</h1>
</div>
<div class="login_wrap">
	<div class="container">
		<div class="row">
			<div class="col-md-8"></div>
			<div class="col-md-4">

				<!-- login start -->
				<div class="login-box">
					<h6>用户登录</h6>
					<form action="javascript:;" method="post" id="inputForm" name="inputForm" class="inputForm">
						<input id="password_form" name="password" type="hidden" />
						<input id="randCode_form" name="rand" type="hidden" />
						<input id="username_form" name="username" type="hidden" />
						<div class="form-group has-feedback">
							<input id="userEname" class="form-control" tabindex="1"
								   placeholder="输入登录用户名" type="text" value="${sysEname}_admin" maxlength="30"/> <span
								class="fa fa-user form-control-feedback"></span>
						</div>
						<div class="form-group has-feedback">
							<input type="password" id="upass" tabindex="2" class="form-control fft"
								   placeholder="输入登录密码" value="" maxlength="30"> <span
								class="fa fa-lock form-control-feedback"></span>
						</div>

						<div class="form-group has-feedback">
							<input id="rand" size="4" tabindex="3" style="width:50%; margin-right:5px;"
								   class="form-control" placeholder="输入验证码" maxlength="6"> <input name="flagDiv"
																								  id="flagDiv" type="hidden" value="" /> <img border="0"
																																			  id="verifyCode" src="" onclick="viewVerifyCode();" align="absmiddle" />
							<script>
                                viewVerifyCode();
							</script>
							<span class="fa fa-pencil form-control-feedback"></span>
						</div>
					</form>
					<div class="tools">
						<div id="error-message" class="col-xs-6 col-sm-7 msg"></div>
					</div>
					<div class="login_btn">
						<div class="text-center">
							<button id="btn-login" type="button" class="btn btn-block btn-primary f16" onclick="sumbit()">登 录</button>
						</div>
					</div>
					<!-- /.login-box-body -->
					<!-- login end -->

				</div>
			</div>
		</div>
	</div>
</div>
<!-- foot start -->
<center>
	<footer class="login-footer text-center" style="margin-top:10px; margin-bottom:10px;">
		<p class="col-sm-12 ">版权所有 &copy;${.now?string("yyyy")} </p>
	</footer>
</center>
<!-- foot start -->

</body>

<script type="text/javascript">
    //解决ie不支持trim
    $(document).ready(
        function(){
            $("#userEname").focus();
            if(!String.prototype.trim) {
                String.prototype.trim = function () {
                    return this.replace(/^\s+|\s+$/g,'');
                };
            }
        }
    );
    //回车登录
    document.onkeydown=function mykeyDown(e){
        //compatible IE and firefox because there is not event in firefox
        e = e || window.event;//兼容IE8
        if(e.keyCode == 13) {sumbit();}
        return;
    };
    //登录操作
    function sumbit(){
        var uname = $('#userEname').val();
        var upass = $('#upass').val();
        if(uname==null|| uname==""){
            setErrMsg('请输入用户名');
            $('#userEname').focus();
            return;
        }
        if(upass==null|| upass==""){
            setErrMsg('请输入密码');
            $('#upass').focus();
            return;
        }
        var index_load = layer.load(1, {shade: false});
        $("#password_form").val(upass.md5());
        $("#randCode_form").val($("#rand").val());
        $("#username_form").val(uname);
        var formUrl =ctx+"/res/login";
        //数据提交
        $.ajax({
            url:formUrl,
            type:'post',
            data: $("#inputForm").serialize(),
            success:function(data){
				console.log(data);
				var jdata = jQuery.parseJSON(data);
                if (jdata.flag == 'T') {
                    //使用此种方式防止外部系统登录无法跨域访问
                    window.location.href="${r'${ctx}'}/sendPage/${sysEname}/admin/index";
                } else {
                    setErrMsg(jdata.msg);
                    clearForm();
                }
                layer.close(index_load);
            },error:function(data){
                layer.close(index_load);
                setErrMsg('与服务器连接失败');
            }
        });
    }

    //清空表单数据
    function clearForm(){
        $("#upass").val("");
        $("#userEname").val("");
    }

    function setErrMsg(msg){
        $("#error-message").html("<font color='red'>"+msg+"</font>");
    }
</script>
</html>
